package com.dinzeer.sjapadder.se;



import com.dinzeer.legendreliclib.effect.LReffect;
import com.dinzeer.legendreliclib.lib.compat.slashblade.Drives;
import com.dinzeer.legendreliclib.lib.event.TypeMakerPressedEvent;
import com.dinzeer.legendreliclib.lib.util.slashblade.SlashBladeUtil;
import com.dinzeer.sjapadder.register.SjaSlashArtRegistry;
import com.dinzeer.sjapadder.register.SjaSpecialEffectRegsitry;
import mods.flammpfeil.slashblade.SlashBlade;
import mods.flammpfeil.slashblade.capability.concentrationrank.ConcentrationRankCapabilityProvider;
import mods.flammpfeil.slashblade.capability.slashblade.ISlashBladeState;
import mods.flammpfeil.slashblade.entity.EntityDrive;
import mods.flammpfeil.slashblade.event.SlashBladeEvent;
import mods.flammpfeil.slashblade.item.ItemSlashBlade;
import mods.flammpfeil.slashblade.registry.ComboStateRegistry;
import mods.flammpfeil.slashblade.registry.specialeffects.SpecialEffect;
import mods.flammpfeil.slashblade.slasharts.Drive;
import mods.flammpfeil.slashblade.util.KnockBacks;
import mods.flammpfeil.slashblade.util.VectorHelper;
import net.minecraft.ChatFormatting;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
// 新增导入：用于文本提示
import net.minecraft.network.chat.Component;

@Mod.EventBusSubscriber
public class FireDanceSE extends SpecialEffect {
    public FireDanceSE() {
        super(30);
    }

    // 新增：左键点击事件处理器
    @SubscribeEvent
    public static void onLeftClick(TypeMakerPressedEvent event) {
            Player player = event.getEntity();
            // 检查特殊效果是否生效
            if (!SpecialEffect.isEffective(SjaSpecialEffectRegsitry.FireDance.getId(), player.experienceLevel)
            ||!SlashBladeUtil.hasSpecialEffect(player.getMainHandItem(), SjaSpecialEffectRegsitry.FireDance)
            ) {
                return;
            }
            // 执行changesa并添加文字提示
            changesa(player);

    }
    @SubscribeEvent
    public static void onUpdateEvent(SlashBladeEvent.UpdateEvent event) {
        if (event.getEntity() instanceof LivingEntity l&&( l.getMainHandItem().getItem() instanceof ItemSlashBlade)){
            if (SlashBladeUtil.hasSpecialEffect(l.getMainHandItem(), SjaSpecialEffectRegsitry.FireDance)){
                if (event.getEntity() instanceof Player player){
                    player.addEffect(new MobEffectInstance(MobEffects.DAMAGE_BOOST, 300, 0));
                }
            }
        }
    }
    @SubscribeEvent
    public static void onDoSlashEvent(SlashBladeEvent.DoSlashEvent event) {
        if (event.getUser() instanceof LivingEntity){
            if (SlashBladeUtil.hasSpecialEffect(event.getBlade(), SjaSpecialEffectRegsitry.FireDance)){
                if (event.getUser() instanceof Player player){
                 if (!SpecialEffect.isEffective(SjaSpecialEffectRegsitry.FireDance.getId(), player.experienceLevel)){return;}
                }

                //spawnCircularDrives方法的倍率是均分的
                Drives.spawnCircularDrives(event.getUser(),8, (float) event.getDamage(),event.getRoll(),10);
                if (SlashBladeUtil.getState(event.getBlade()).getComboSeq().equals(ComboStateRegistry.COMBO_B1.getId())){
                    SlashBladeUtil.getState(event.getBlade()).setComboSeq(SjaSlashArtRegistry.Dance.get().getComboState(event.getUser()));
                }
            }
        }
    }






    private static void changesa(Player player) {
        if (!player.level().isClientSide){

        ISlashBladeState state= SlashBladeUtil.getState(player.getMainHandItem());
        if (state.getSlashArtsKey().equals(SjaSlashArtRegistry.Dance.getId())){
            state.setSlashArtsKey(SjaSlashArtRegistry.BurningDances.getId());
        }else if (state.getSlashArtsKey().equals(SjaSlashArtRegistry.BurningDances.getId())){
            state.setSlashArtsKey(SjaSlashArtRegistry.Dance.getId());
        }
        player.sendSystemMessage(Component.translatable("message.sajp_adder.firedance").withStyle(ChatFormatting.RED));
        }
    }
}
